package com.gitee.ywj1352.client.factory.impl;


import com.gitee.ywj1352.client.ClientFactory;
import com.gitee.ywj1352.client.ClientParser;
import com.gitee.ywj1352.common.util.ClientStructure;

import java.util.concurrent.ConcurrentHashMap;

/**
 * use jdk for proxy object init
 * class HiClient{
 * String sayHi(String name);
 * }
 */
public class DefaultClientFactory implements ClientFactory {

    private ClientParser parser;

    public DefaultClientFactory(ClientParser parser) {
        this.parser = parser;
    }

    private ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<>();

    @Override
    public <T> T getClient(Class<T> clientClazz, String clientName) {
        // find cache just return
        if (clientCache.containsKey(clientName)) {
            return clientClazz.cast(clientCache.get(clientName));
        }
        ClientStructure clientStructure = parser.parse(clientClazz);


        return null;
    }

    /**
     *  创建一个proxy client
     * @param clientStructure
     * @return
     */
    public Object generateClient(ClientStructure clientStructure) {






        return null;
    }


}
